package com.newtouch.ainsurtech.batch.job.demo;/**
 * Created by jovi on 27/09/2017.
 */

import com.newtouch.ainsurtech.batch.job.demo.tasklet.HelloTasklet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.core.launch.support.RunIdIncrementer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * <p>
 * Title:
 * </p>
 * <p>
 * Description:
 * </p>
 * <p>
 * Copyright: Copyright (c) 2016
 * All rights reserved. 2017-09-27 10:34
 * </p>
 *
 * @author MaoJiaWei
 * @version 1.0
 */
@Component
public class PersonJob {

    private Logger log = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private JobBuilderFactory jobs;

    @Autowired
    private StepBuilderFactory steps;

    public Job demoJob() {
        log.info("--------Starting demoJob now-->" + new Date());
        return jobs.get("demoJob")
                .incrementer(new RunIdIncrementer())
                .preventRestart()
                .flow(demoStep())
                .end()
                .build();
    }

    protected Step demoStep() {
        log.info("-------Starting demoStep-------");
        return steps.get("demoStep")
                .tasklet(new HelloTasklet())
                .allowStartIfComplete(true)
                .build();
    }

}
